home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_02_10 / 2n10046a < prev    next >
Text File  |  1991-01-27  |  21KB  |  632 lines

  1.     Page    60,132
  2. ;---------------------------------------------------------------
  3. ;               BEGIN LISTING 3
  4. ;---------------------------------------------------------------
  5. ;
  6. ; EMULOAD.ASM    Copyright (c) 1991 Robert Collins
  7. ;
  8. ;    This utility uses '386 LOADALL to emulate '286 LOADALL.
  9. ;    All 16-bit registers are zero-extended to 32-bit
  10. ;    registers.  All 24-bit physical addresses are zero-
  11. ;    extended to 32-bit registers.  '386-specific registers
  12. ;    not used in '286 LOADALL are either set to the current
  13. ;    values (Debug registers), or zeroed (segment registers).
  14. ;
  15. ;---------------------------------------------------------------
  16. ;
  17. ;    This program assumes that you have run the '386 LOADALL
  18. ;    test prior to installing this TSR.  Obviously if LOADALL
  19. ;    has been removed from the '386 mask, then this program
  20. ;    will never work.  Likewise, it is easier for me to
  21. ;    document the need to run the LOADALL test program, than
  22. ;    to incorporate it into this code.
  23. ;
  24. ;---------------------------------------------------------------
  25. ;
  26. ;    EMULOAD returns ERROR codes to DOS that can be
  27. ;    intecepted by the batch file command 'IF ERRORLEVEL'.
  28. ;    The following ERRORLEVEL codes are generated by this
  29. ;    program:
  30. ;      0 = EMULOAD driver now installed in memory
  31. ;      1 = Attempted removal of the EMULOAD driver from
  32. ;          memory failed because EMULOAD was not in already
  33. ;          in memory.
  34. ;      2 = The EMULOAD driver was already in memory when an
  35. ;          attempt was made to install it again.
  36. ;      3 = Bogus command line argument(s).
  37. ;      4 = Help requested.
  38. ;      5 = The EMULOAD driver was sucessfully removed from
  39. ;          memory.
  40. ;      6 = Can't install the EMULOAD driver because this
  41. ;          computer isn't an 80386.
  42. ;
  43. ;---------------------------------------------------------------
  44. ;
  45. ;    Compilation instructions:
  46. ;        MASM EMULOAD;        (MASM 5.1)
  47. ;        LINK EMULOAD;
  48. ;        EXE2BIN EMULOAD EMULOAD.COM
  49. ;        DEL EMULOAD.EXE
  50. ;
  51. ;    The resultant EMULOAD.COM file is 1473 bytes, while the
  52. ;    TSR portion is 1072 bytes.
  53. ;
  54. ;---------------------------------------------------------------
  55. ; Compiler directives
  56. ;---------------------------------------------------------------
  57.     Title    EMULOAD
  58.     .radix    16
  59.     .8086
  60.  
  61. ;---------------------------------------------------------------
  62. ; Interrupt vector segment
  63. ;---------------------------------------------------------------
  64. ABS0    segment at 0
  65.     org 6*4
  66.     INT_6    dd    ?
  67.  
  68.     org 800h
  69.     Loadall_286    dd    ?
  70. ABS0    ends
  71.  
  72.  
  73. ;---------------------------------------------------------------
  74. ; Structure definitions
  75. ;---------------------------------------------------------------
  76. Desc_cache2    STRUC            ; 80286 Descriptor cache
  77.     A15_A00 dw    ?        ;  register layout.
  78.     A23_A16 db    ?
  79.     _Type2    db    ?
  80.     _Limit2 dw    ?
  81. Desc_cache2    ENDS
  82.  
  83.  
  84. Desc_cache3    STRUC            ; 80386 Descriptor cache
  85.     _Access db    0        ;  register layout
  86.     _Type    db    ?
  87.     _CS32    db    0
  88.         db    0
  89.     _Addr    dd    ?
  90.     _Limit    dd    ?
  91. Desc_cache3    ENDS
  92.  
  93.  
  94.  
  95. Loadall_struc2    STRUC            ; 80286 LOADALL table
  96.             dw    3 dup (?)    ; RESERVED
  97.     _286Msw     dw    ?        ; MSW
  98.             dw    7 dup (?)    ; RESERVED
  99.     _286Tr        dw    ?        ; TR
  100.     _Flags        dw    ?        ; FLAGS
  101.     _286Ip        dw    ?        ; IP
  102.     _286Ldt     dw    ?        ; LDT
  103.     _286Ds        dw    ?        ; DS
  104.     _286Ss        dw    ?        ; SS
  105.     _286Cs        dw    ?        ; CS
  106.     _286Es        dw    ?        ; ES
  107.     _286Di        dw    ?        ; DI
  108.     _286Si        dw    ?        ; SI
  109.     _286Bp        dw    ?        ; BP
  110.     _286Sp        dw    ?        ; SP
  111.     _286Bx        dw    ?        ; BX
  112.     _286Dx        dw    ?        ; DX
  113.     _286Cx        dw    ?        ; CX
  114.     _286Ax        dw    ?        ; AX
  115.     ES_Desc286    dw    3 dup (?)    ; ES Desc. Cache
  116.     CS_Desc286    dw    3 dup (?)    ; CS Desc. Cache
  117.     SS_Desc286    dw    3 dup (?)    ; SS Desc. Cache
  118.     DS_Desc286    dw    3 dup (?)    ; DS Desc. Cache
  119.     Gdt_Desc286    dw    3 dup (?)    ; GDTR
  120.     Ldt_Desc286    dw    3 dup (?)    ; LDTR
  121.     Idt_Desc286    dw    3 dup (?)    ; IDTR
  122.     TSS_Desc286    dw    3 dup (?)    ; TSSR
  123. Loadall_Struc2    ENDS
  124.  
  125. Loadall_struc3    STRUC
  126.     _Cr0        dd    ?        ; EAX
  127.     _Eflags     dd    ?        ; EFLAGS
  128.     _Eip        dd    ?        ; EIP
  129.     _Edi        dd    ?        ; EDI
  130.     _Esi        dd    ?        ; ESI
  131.     _Ebp        dd    ?        ; EBP
  132.     _Esp        dd    ?        ; ESP
  133.     _Ebx        dd    ?        ; EBX
  134.     _Edx        dd    ?        ; EDX
  135.     _Ecx        dd    ?        ; ECX
  136.     _Eax        dd    ?        ; EAX
  137.     _Dr6        dd    ?        ; DR6
  138.     _Dr7        dd    ?        ; DR7
  139.     _Tr        dd    ?        ; TR
  140.     _Ldt        dd    ?        ; LDT
  141.     _Gs        dd    ?        ; GS
  142.     _Fs        dd    ?        ; FS
  143.     _Ds        dd    ?        ; DS
  144.     _Ss        dd    ?        ; SS
  145.     _Cs        dd    ?        ; CS
  146.     _Es        dd    ?        ; ES
  147.     TSS_Desc    dd    3 dup (?)    ; TSSR
  148.     IDT_Desc    dd    3 dup (?)    ; IDTR
  149.     Gdt_Desc    dd    3 dup (?)    ; GDTR
  150.     Ldt_Desc    dd    3 dup (?)    ; LDTR
  151.     GS_Desc     dd    3 dup (?)    ; GS Desc. Cache
  152.     FS_Desc     dd    3 dup (?)    ; FS Desc. Cache
  153.     DS_Desc     dd    3 dup (?)    ; DS Desc. Cache
  154.     SS_Desc     dd    3 dup (?)    ; SS Desc. Cache
  155.     CS_Desc     dd    3 dup (?)    ; CS Desc. Cache
  156.     ES_Desc     dd    3 dup (?)    ; ES Desc. Cache
  157.             dd    0ah dup (?)    ; RESERVED
  158. Loadall_Struc3    ENDS
  159.  
  160. INT_VEC     STRUC
  161.     int_offset    dw    ?
  162.     int_segment    dw    ?
  163. INT_VEC     ENDS
  164.  
  165.  
  166. ;---------------------------------------------------------------
  167. ; Equate definitions
  168. ;---------------------------------------------------------------
  169.     LOADALL286    equ    050fh
  170.     CRLF        equ    <0dh,0ah>
  171.     CRLF$        equ    <0dh,0ah,'$'>
  172.     INT6        equ    [bp-4]
  173.  
  174.  
  175. ;---------------------------------------------------------------
  176. ; Macro definitions
  177. ;---------------------------------------------------------------
  178.     LOADALL_386    MACRO
  179.         db    0fh,07h
  180.     ENDM
  181.  
  182.  
  183.     PRINT_STRING    MACRO    MSG_NAME
  184.     mov    ah,9
  185.     mov    dx,offset MSG_NAME
  186.     int    21h
  187.     ENDM
  188.  
  189.  
  190.  
  191. _TEXT    SEGMENT PARA PUBLIC 'CODE'
  192.     Assume    CS:_TEXT, DS:_TEXT, ES:_TEXT, SS:_TEXT
  193.     Org    100h
  194.     .386p
  195. ;---------------------------------------------------------------
  196.   Emulate_286_Loadall    Proc    Far
  197. ;---------------------------------------------------------------
  198.     jmp    EMULOAD     ; goto beginning instruction
  199.  
  200. Align 4
  201. ;---------------------------------------------------------------
  202. ; Local Data
  203. ;---------------------------------------------------------------
  204. Loadall_tbl    Loadall_Struc3 <>
  205.  
  206. emuload_msg    db    "80286 LOADALL EMULATOR utility.",CRLF
  207.         db    "Version 1.0 Only for 80386 computers."
  208.         db    CRLF
  209.         db    "Copyright (c) 1991 Robert Collins."
  210.         db    CRLF$
  211. emu_msg_len    equ    $-emuload_msg
  212.  
  213. align 4
  214. ;---------------------------------------------------------------
  215. ; TSR Code begins here as an INT06 replacement.
  216. ;---------------------------------------------------------------
  217. Int06:    push    bp
  218.     mov    bp,sp
  219.     push    si
  220.     push    ds
  221.     lds    si,[bp][2]        ; get CS:IP of bogus
  222.                     ;  opcode
  223.     cmp    word ptr [si],LOADALL286; was it LOADALL?
  224.     jne    @Not_LOADALL        ; nope
  225.     mov    di,0
  226.     mov    ds,di
  227.     mov    di,cs
  228.     mov    es,di
  229.     mov    edi,offset Loadall_tbl
  230.  
  231. Assume    DS:ABS0, ES:_TEXT, SS:NOTHING
  232. ;---------------------------------------------------------------
  233. ; Convert 80286 registers to 80386 counterparts.  The sequencing
  234. ; order follows the 80386 LOADALL table.
  235. ;---------------------------------------------------------------
  236. ; While mapping MSW to CR0, bit5 in CR0 is documented as
  237. ; RESERVED on the '386 DX, and '1' on the '386 SX.  Bit6 is
  238. ; defined as 'NE' (Numeric Exception) on the '486.  If we wanted
  239. ; this code to work on the '486, then we should mask the lower
  240. ; nibble of MSW with CR0.  But the '486 doesn't have LOADALL,
  241. ; so this isn't necesary.  Next consider the Reserved bit5 on
  242. ; the '386 DX.  Since LOADALL completely redefines the CPU
  243. ; state, it is safe to clear this reserved bit instead of
  244. ; masking it with MSW.
  245. ;---------------------------------------------------------------
  246.     mov    eax,cr0         ; MSW    --> CR0
  247.     mov    ax,Loadall_286._286Msw
  248.     mov    Loadall_tbl._CR0,eax
  249.     movzx    eax,Loadall_286._Flags    ; FLAGS --> EFLAGS
  250.     mov    Loadall_tbl._EFLAGS,eax
  251.  
  252. ;---------------------------------------------------------------
  253. ; Hereafter MOVZX isn't needed because the upper 16-bits are
  254. ; guaranteed to be 0.
  255. ;---------------------------------------------------------------
  256.     mov    ax,Loadall_286._286IP    ; IP    --> EIP
  257.     mov    Loadall_tbl._EIP,eax
  258.     mov    ax,Loadall_286._286DI    ; DI    --> EDI
  259.     mov    Loadall_tbl._EDI,eax
  260.     mov    ax,Loadall_286._286SI    ; SI    --> ESI
  261.     mov    Loadall_tbl._ESI,eax
  262.     mov    ax,Loadall_286._286BP    ; BP    --> EBP
  263.     mov    Loadall_tbl._EBP,eax
  264.     mov    ax,Loadall_286._286SP    ; SP    --> ESP
  265.     mov    Loadall_tbl._ESP,eax
  266.     mov    ax,Loadall_286._286BX    ; BX    --> EBX
  267.     mov    Loadall_tbl._EBX,eax
  268.     mov    ax,Loadall_286._286DX    ; DX    --> EDX
  269.     mov    Loadall_tbl._EDX,eax
  270.     mov    ax,Loadall_286._286CX    ; CX    --> ECX
  271.     mov    Loadall_tbl._ECX,eax
  272.     mov    ax,Loadall_286._286AX    ; AX    --> EAX
  273.     mov    Loadall_tbl.